package cn.usian.jyzx.product.controller;

import cn.usian.jyzx.model.dto.h5.ProductSkuDto;
import cn.usian.jyzx.model.entity.product.Category;
import cn.usian.jyzx.model.entity.product.ProductSku;
import cn.usian.jyzx.model.vo.common.Result;
import cn.usian.jyzx.model.vo.common.ResultCodeEnum;
import cn.usian.jyzx.model.vo.h5.IndexVo;
import cn.usian.jyzx.model.vo.h5.ProductItemVo;
import cn.usian.jyzx.product.service.CategoryService;
import cn.usian.jyzx.product.service.ProductService;
import cn.usian.jyzx.product.service.ProductSkuService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/product")
@Tag(name = "商品相关的接口")
public class ProductController {
    @Autowired
    ProductService productService;
    @Autowired
    CategoryService categoryService;
    @Autowired
    ProductSkuService productSkuService;
    @Operation(summary = "查询首页数据")
    @GetMapping("index")
    public Result<IndexVo> findall(){
        IndexVo indexVo  = productService.findall();
        return Result.build(indexVo, ResultCodeEnum.SUCCESS);
    }
    @GetMapping("category/findCategoryTree")
    @Operation(summary = "三级分类树查询")
    public Result<List<Category>> findCategoryTree(){
        List<Category> categoryList = categoryService.findCategoryTree();
        return Result.build(categoryList,ResultCodeEnum.SUCCESS);
    }

    @GetMapping("{page}/{limit}")
    public Result<PageInfo<ProductSku>> findpage(@PathVariable Integer page, @PathVariable Integer limit, ProductSkuDto productSkuDto){
       PageInfo<ProductSku> pageInfo =  productService.findpage(page,limit,productSkuDto);
       return Result.build(pageInfo,ResultCodeEnum.SUCCESS);
    }

    @GetMapping("item/{skuId}")
    public Result<ProductItemVo> item(@PathVariable Long skuId){
        ProductItemVo productItemVo =productService.item(skuId);
        return Result.build(productItemVo,ResultCodeEnum.SUCCESS);
    }
    @GetMapping("getBySkuId/{skuId}")
    public ProductSku getBySkuId(@PathVariable Integer skuId){
        return productSkuService.getBySkuId(skuId);
    }
}
